<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/7/23 0023
 * Time: 10:43
 */

class Log
{
    private static $instance = null;
    private static $path = 'Logs';
    private static $file = '';
    private function __construct()
    {
        $date = date('Y-m-d');
        self::$file = self::$path.DIRECTORY_SEPARATOR.$date.'.txt';
        if(!file_exists(self::$file)){
            file_put_contents(self::$file,'');
        }
    }

    public static function instance()
    {
        if(self::$instance === null){
            self::$instance = new Log();
        }
        return self::$instance;
    }

    public function add($data,$type)
    {
        $insert = sprintf('[ %s ] %s: %s',date('Y-m-d H:i:s'),$type,$data);
        file_put_contents(self::$file,$insert,FILE_APPEND);
    }
    public function info($data)
    {
        $this->add($data,'info');
    }
    public function error($data)
    {
        $this->add($data,'info');
    }
}